package org.yray.sip.factory.impl;

import org.springframework.stereotype.Component;
import org.yray.sip.base.MsgType;
import org.yray.sip.base.SipMsg;
import org.yray.sip.creator.MessageCreator;
import org.yray.sip.factory.inet.IAction;
import org.yray.sip.log.AbstractLog;
import org.yray.sip.rtp.receive.AbstractBeanHolder;
import org.yray.sip.rtp.sender.ISipSessionCache;
import org.yray.sip.server.SipSession;
import org.yray.sip.utils.IcspBeanHolder;

/***
 * 只解决用来发bye报文的情况
 */
@Component
public class ActionByeA extends AbstractBeanHolder implements IAction {




    @Override
    public void action(SipMsg sipMsg)
    {
        AbstractLog.log(sipMsg.getCallId(),"ActionBye","begin");
        String aId=getIdRuleComponent().getAIdFromAOrBId(sipMsg.getCallId());
        SipSession sipSession= IcspBeanHolder.getBean(ISipSessionCache.class).get(aId);
        if (sipSession!=null&&sipSession.getBye().compareAndSet(false,true))
        {
            String msgBye = MessageCreator.getCreator(MsgType.BYE).createMsg(sipSession);
            getSipServerHandler(sipSession.getCallId()).sendToSipServer(sipSession,msgBye);
        }

    }
}
